package com.example.tests;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.Set;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

public class GroupModeTests extends SuperClass {

	Random rnd = new Random();

	@DataProvider(name = "randomGroups")
	public Iterator<Object[]> generateRandomGroups() {
		List<Object[]> list = new ArrayList<Object[]>();
		for (int i = 0; i < 5; i++) {
			GroupObject group = new GroupObject()
					.setName("Group_name_mode" + rnd.nextInt())
					.setHeader("Group_header_mode" + rnd.nextInt())
					.setFooter("Group_footer_mode" + rnd.nextInt());
			list.add(new Object[] { group });
		}
		return list.iterator();
	}

	@Test(dataProvider = "randomGroups")
	public void testGroupModeTrue(GroupObject addGroup) throws Exception {
		Set<GroupObject> existList = app.getGroupHelper().getGroups();
		app.getGroupHelper().modeGroup(1, addGroup);// action
		Set<GroupObject> newList = app.getGroupHelper().getGroups();
		verifyGroupMode(existList, addGroup, newList);
	}

	private void verifyGroupMode(Set<GroupObject> existList,
			GroupObject addGroup, Set<GroupObject> newList) {
		assertThat(newList.size(), equalTo(existList.size()));

	}
}
